<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<button type="button" class="begin">开启定时器</button>
		<button type="button" class="stop">停止定时器</button>
		<script type="text/javascript">
			var begin = document.querySelector(".begin");
			var stop = document.querySelector(".stop");
			var timer = null;
			var i = 0;
			begin.addEventListener("click", function() {
				timer = setInterval(function() {
					i = i + 1;
					console.log(i);
				}, 1000);
			});

			stop.addEventListener("click", function() {
				clearInterval(timer);
			})
		</script>
	</body>
</html>
